package com.sczmgk.hotline.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.sczmgk.hotline.constant.Constant;
import com.sczmgk.hotline.utils.MyLog;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2017/6/23.
 */

public class MsgTimerService extends Service {
    private static final String TAG = MsgTimerService.class.getSimpleName();
    private boolean isAndroid = true;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        MyLog.i(TAG,"bindService  isAndroid: "+isAndroid);
        return new Mybinder();
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);

    }

    /**
     * 是否为机器人聊天
     * @param b
     */
    public void startTimer(boolean b) {
        this.isAndroid = b;
        MyLog.d(TAG,"starttimer  isAndroid: "+isAndroid);
        if(!isAndroid){
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    isAndroid = true;
                    MyLog.e(TAG,"timer cancel: "+isAndroid);
                }
            }, Constant.DELAY_TIME);
        }

    }

    public class  Mybinder extends Binder {
         public MsgTimerService getService(){
             return MsgTimerService.this;
         }
    }
    public boolean isAndroid(){
        MyLog.i(TAG,"get   isAndroid: "+isAndroid);
        return isAndroid;
    }

    public void cancelTimer(){
        isAndroid = true;
        MyLog.e(TAG,"cancelTimer  isAndroid: "+isAndroid);
    }
}
